//
//  TaobaoAuthorView.m
//  Cat
//
//  Created by 卢仕彤 on 2019/4/5.
//  Copyright © 2019 lushitong. All rights reserved.
//

#import "TaobaoAuthorView.h"
#import "QKShareLiveSheetManager.h"

@interface TaobaoAuthorView()

@property (nonatomic, strong) UIView *operView;
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) UIImageView *taobaoImageView;
@property (nonatomic, strong) UILabel *taobaoLabel;
@property (nonatomic, strong) UILabel *taobaoInfoLabel;
@property (nonatomic, strong) UIButton *colorButton;

@property (nonatomic, copy) void(^anthoreBlock)(void);
@end

@implementation TaobaoAuthorView

-(void)pushAnthoreBlock:(void(^)(void))AnthoreBlock {
    self.anthoreBlock = AnthoreBlock;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self loadSubviews];
    }
    return self;
}

- (void)loadSubviews {
    [self addSubview:self.operView];
    [self.operView addSubviews:@[self.closeButton,self.taobaoImageView,self.taobaoLabel,self.taobaoInfoLabel,self.colorButton]];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.operView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.taobaoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kQKFitModuleDecimal(70.0), kQKFitModuleDecimal(70.0)));
        make.centerX.equalTo(self.operView.mas_centerX);
        make.top.equalTo(self.operView.mas_top).offset(kQKFitModuleDecimal(25.0));
    }];
    
    [self.taobaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.operView.mas_centerX);
        make.top.equalTo(self.taobaoImageView.mas_bottom).offset(kQKFitModuleDecimal(10.0));
    }];
    
    [self.taobaoInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.taobaoLabel.mas_bottom).offset(kQKFitModuleDecimal(10.0));
        make.centerX.equalTo(self.taobaoImageView.mas_centerX);
        make.left.greaterThanOrEqualTo(self.operView.mas_left).offset(kQKFitModuleDecimal(22));
        make.right.lessThanOrEqualTo(self.operView.mas_right).offset(-kQKFitModuleDecimal(22));
    }];
    
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kQKFitModule(35), kQKFitModule(35)));
        make.top.equalTo(self.operView.mas_top);
        make.right.equalTo(self.operView.mas_right);
    }];
    
    [self.colorButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.operView.mas_left).offset(kQKFitModuleDecimal(21));
        make.right.equalTo(self.operView.mas_right).offset(-kQKFitModuleDecimal(21));
        make.bottom.equalTo(self.operView.mas_bottom).offset(-kQKFitModuleDecimal(25));
        make.height.equalTo(@(kQKFitModuleDecimal(40.0)));
    }];
}

- (void)closeButtonAction {
    [QKShareLiveSheetManager dissMissAnthoreInvite];
}

- (void)pushTaoBaoAnthor {
    if (self.anthoreBlock) {
        [QKShareLiveSheetManager dissMissAnthoreInvite];
        self.anthoreBlock();
    }
}

#pragma mark lazy init

- (UIView *)operView {
    if (!_operView) {
        _operView = [[UIView alloc] init];
        _operView.backgroundColor = [UIColor whiteColor];
    }
    return _operView;
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _closeButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_closeButton setImage:[UIImage imageNamed:@"dhf_alert_close"] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(closeButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}

- (UIImageView *)taobaoImageView {
    if (!_taobaoImageView) {
        _taobaoImageView = [[UIImageView alloc] init];
        _taobaoImageView.image = [UIImage imageNamed:@"taobao_info.jpg"];
    }
    return _taobaoImageView;
}

- (UILabel *)taobaoLabel {
    if (!_taobaoLabel) {
        _taobaoLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:kQKFitModuleDecimal(17)] textColor:[UIColor blackColor]];
        _taobaoLabel.text = @"请完成淘宝授权";
    }
    return _taobaoLabel;
}

- (UILabel *)taobaoInfoLabel {
    if (!_taobaoInfoLabel) {
        _taobaoInfoLabel = [UILabel labelWithText:@"淘宝授权后下单货分享产品可以获得收益哦" font:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0x333333)];
        _taobaoInfoLabel.numberOfLines = 0;
    }
    return _taobaoInfoLabel;
}

- (UIButton *)colorButton {
    if (!_colorButton) {
        _colorButton = [UIButton buttonWithTitle:@"去授权" color:[UIColor whiteColor] font:[UIFont systemFontOfSize:kQKFitFont(12)] normalImage:[UIImage createImageWithSize:CGSizeMake(ScreenWidth - kQKFitModuleDecimal(64), kQKFitModuleDecimal(40)) gradientColors:@[COLOR_WITH_RGB(255, 129, 10),COLOR_WITH_RGB(253, 55, 1)] percentage:@[@(0),@(1)] gradientType:GradientFromLeftToRight] cornerRadius:kQKFitModuleDecimal(20.0)];
        [_colorButton addTarget:self action:@selector(pushTaoBaoAnthor) forControlEvents:UIControlEventTouchUpInside];
    }
    return _colorButton;

}

@end
